<template>
	<view class="content">
		<view class="status-list flex">
			<view :key="index" class=" " @click="onType(item.status)" :class="[item.status == status ? 'active' : '']" v-for="(item,index) in typeItem">
				{{item.title}}
			</view>
		</view>
		<view class="bill-list">
			<view class="bill-li po " v-for="(item,index) in items" :key="index" >
				<view class="flex">
					<text class="bill-tips">
						余额提现
					</text>
					<text class="active">
						实际到账总额：{{amountNum(item.amount,item.fee)}}
					</text>
				</view>
				<view class="flex">
					<text class="colorc">
						{{forDate(item.created_at)}}
					</text>
					<text class="active">
						提现总额：{{item.amount}}，手续费：{{item.fee}} 
					</text>
				</view>
			</view>
		</view>
		<uni-load-more :status="moreStatus" />
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue'
	
	import {
        mapState,
        mapMutations
    } from 'vuex'
	
	export default {
		computed: {
            ...mapState(['token'])
        },
		components: {
			uniLoadMore
		},
		data() {
			return {
				typeItem: [
					{
						"title":"待审核",
						"status":"0"
					},{
						"title":"待打款",
						"status":"1"
					},
					{
						"title":"已打款",
						"status":"2"
					},
					{
						"title":"被驳回",
						"status":"3"
					}
				],
				status: 0,
				items: [],
				page: 1,
				pageCount: 0,		// 总页数
				moreStatus: 'more',
				loadingStatus: true,
				statusTypes: [{
					value: 'more',
					text: '加载前',
					checked: true
				}, {
					value: 'loading',
					text: '加载中',
					checked: false
				}, {
					value: 'noMore',
					text: '没有更多',
					checked: false
				}],
				statusItem:{
					"0":"待审核",
					"1":"待打款",
					"2":"已打款",
					"3":"驳回"
				},
			}
		},
		onShow() {
			if(this.token) 
			this.onType(this.status)
		},
		methods: {
			...mapMutations(['getNetworkType','vuexRequest']),
			onType(t) {
				this.status = t
				this.page = 1
				this.loadingStatus = true
				this.getlist()
			},
			getlist() {
				if(!this.loadingStatus){	//防止重复请求
					return !1
				}
				//
				this.loadingStatus = false
				this.moreStatus = 'loading'
				this.vuexRequest({
					url: '/api/v2/member/withdraw/index?access-token=' + this.token,
					method: 'GET',
					data: {pay_state:this.status,page:this.page,"per-page":20},
					success: (res)  => {
						this.loadingStatus = true
						// 
						if(this.page == 1){
							this.items = res.data.data.list
						}else{
							this.items = this.items.concat(res.data.data.list)
						}						
						
						// 分页信息
						this.page++
						this.pageCount = res.data.data.pageInfo.pageCount
						// 判断分页
						if(this.page > this.pageCount){
							this.moreStatus = 'noMore'
						}else{
							this.moreStatus = 'more'
							this.loadingStatus = true
						}
					},
					fail: (err)  => {
					},
				})
			},
			forDate(time) {
				let date = new Date(time * 1000); 		//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let Y = date.getFullYear() + '-';
				let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				let D = this.change(date.getDate()) + ' ';
				let h = this.change(date.getHours()) + ':';
				let m = this.change(date.getMinutes()) + ':';
				let s = this.change(date.getSeconds());
				return Y + M + D + h + m + s;
			},
			change(t) {
				if (t < 10) {
					return "0" + t;
				} else {
					return t;
				}
			},
			amountNum(amount,fee) {
				let num = parseFloat(amount) - parseFloat(fee)
				return num.toFixed(2)
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.getlist()
			// 实际开发中通常是网络请求，加载完数据后就停止。这里仅做演示，加延迟为了体现出效果。
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000);
		},
		onReachBottom() {
			if(this.loadingStatus &&  this.pageCount > this.page ){	//防止重复请求
				this.getlist()
			}else{
				this.moreStatus = 'noMore'
			}
		}
	}
</script>

<style scoped>
	
	.colorc{
		color: #9b9b9b;
		
	}
	.active{
		color: #e73f3f;
		
	}
	.bill-li .active{
		font-size: 24upx;
	}
	.bill-li .colorc{
		font-size: 20upx;
	}
	.flex{
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-orient: horizontal;
		-webkit-box-direction: normal;
		-webkit-flex-direction: row;
		-ms-flex-direction: row;
		flex-direction: row;
		-webkit-box-pack: justify;
		-webkit-justify-content: space-between;
		-ms-flex-pack: justify;
		justify-content: space-between;
		-webkit-box-align: center;
		-webkit-align-items: center;
		-ms-flex-align: center;
		align-items: center;
	}
	.po{
		position: relative;
	}
	.po:after{
		position: absolute;
		z-index: 10;
		right: 0;
		bottom: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		-ms-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}
	.content{
		padding: 0;
	}
	.bill-list{
		padding: 0 0;
		background: #FFFFFF;
	}
	.bill-li{
		padding: 20upx 30upx;
	}
	.bill-tips{
		display: block;
		font-size: 32upx;
	}
	/*  #ifdef  H5  */
	.status-list{
		background: #FFFFFF;
		position: fixed;
		width: 100%;
		max-height: 90upx;
		top: 88upx;
	}
	/*  #endif  */
	/*  #ifdef  APP-PLUS  */
	.status-list{
		background: #FFFFFF;
		position: fixed;
		width: 100%;
		max-height: 90upx;
		top: 0;
	}
	/*  #endif  */
	
	.status-list view{
		width: 25%;
		text-align: center;
		padding: 20upx 0;
		position: relative;
	}
	.status-list view:after{
		position: absolute;
		content: '';
		display: block;
		background: #FFFFFF;	
		width: 64%;
		left: 18%;
		height: 4upx;
		bottom: 0;
	}
	.status-list view.active:after{
		background: #e73f3f;
	}
</style>
